<?php

namespace app\controller\api;

use app\base\BaseEncryptController;
use app\factory\User as UserFacade;
use app\model\business\BusinessModel;
use app\model\user\UserCollectUpModel;
use app\model\user\UserModel;
use think\Request;

/**
 * User
 * Class UserCart
 * @package app\controller
 */
class UserCollect extends BaseEncryptController
{
    protected function initialize()
    {
        parent::initialize();
        $this->model = new UserModel();
    }

    /**
     * 用户收藏和点赞（推荐商品）列表
     * @param Request $request
     * @return \think\response\Json
     */
    public function onUserCollectOrUp(Request $request)
    {
        $formData = $request->param();
        $userInfo = $this->currentUser;//登录信息
        $UserFacade = new UserFacade();
        $res = $UserFacade->userCollectOrUp($formData, $userInfo);
        return self::returnMsg($res);
    }

    /**
     * 点赞-收藏
     * @param Request $request
     * @return \think\response\Json
     */
    public function onGoodsUpOrCollect(Request $request)
    {
        $goods_id = $request->param("goods_id");
        $type = $request->param("type");
        $operation = $request->param("operation");
        $userInfo = $this->currentUser;//登录信息
        $user_collect_up_model = new UserCollectUpModel();
        $res = $user_collect_up_model->apiUpOrCollect($goods_id, $type, $userInfo['user_id'], $operation);
        return self::returnMsg($res);
    }

}
